﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class AdminPages_SuspendRemoveUser : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        TableCell UserName = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0];

        MembershipUser user = Membership.GetUser(Convert.ToString(UserName.Text));

        if(e.CommandName.Equals("suspend"))
        {
            DVDTableAdapters.CustomerTableAdapter ta = new DVDTableAdapters.CustomerTableAdapter();
            ta.UpdateQuery(true, (Guid)user.ProviderUserKey);

            DVDTableAdapters.aspnet_MembershipTableAdapter ta1 = new DVDTableAdapters.aspnet_MembershipTableAdapter();
            ta1.UpdateStatusUser(false, (Guid)user.ProviderUserKey);

        }
        else
        {
            //Delete DVD Database

            //Delete Acual Rent
            DVDTableAdapters.ActualRentTableAdapter ta1 = new DVDTableAdapters.ActualRentTableAdapter();
            ta1.DeleteUser((Guid)user.ProviderUserKey);
            ta1=null;
            //Delete User History
            DVDTableAdapters.UserhistoryMovieTableAdapter ta2 = new DVDTableAdapters.UserhistoryMovieTableAdapter();
            ta2.DeleteUser((Guid)user.ProviderUserKey);
            ta2 = null;
            //Delete Rental List
            DVDTableAdapters.RentalListMoviesTableAdapter ta3 = new DVDTableAdapters.RentalListMoviesTableAdapter();
            ta3.DeleteUser((Guid)user.ProviderUserKey);
            ta3 = null;
            //Delete MessageTable
            DVDTableAdapters.MessageTableAdapter ta10 = new DVDTableAdapters.MessageTableAdapter();
            ta10.DeleteQuery((Guid)user.ProviderUserKey);
            ta10 = null;


            //Delete CustomerTable
            DVDTableAdapters.CustomerTableAdapter ta4 = new DVDTableAdapters.CustomerTableAdapter();
            ta4.DeleteUser((Guid)user.ProviderUserKey);
            
            //Delete User Database

            //Delete Profile
            DVDTableAdapters.aspnet_ProfileTableAdapter ta5 = new DVDTableAdapters.aspnet_ProfileTableAdapter();
            ta5.DeleteUser((Guid)user.ProviderUserKey);
            ta5 = null;

            //Delete Personalization
            DVDTableAdapters.aspnet_PersonalizationPerUserTableAdapter ta6 = new DVDTableAdapters.aspnet_PersonalizationPerUserTableAdapter();
            ta6.DeleteCustomer((Guid)user.ProviderUserKey);
            ta6 = null;

            //Delete UsersInRoles
            DVDTableAdapters.aspnet_UsersInRolesTableAdapter ta7 = new DVDTableAdapters.aspnet_UsersInRolesTableAdapter();
            ta7.DeleteUser((Guid)user.ProviderUserKey);
            ta7 = null;

            //Delete Membership
            DVDTableAdapters.aspnet_MembershipTableAdapter ta8 = new DVDTableAdapters.aspnet_MembershipTableAdapter();
            ta8.DeleteUser((Guid)user.ProviderUserKey);
            ta8 = null;

            //Delete Users
            DVDTableAdapters.aspnet_UsersTableAdapter ta9 = new DVDTableAdapters.aspnet_UsersTableAdapter();
            ta9.DeleteUser((Guid)user.ProviderUserKey);
            ta9 = null;
        
        }
        Response.Redirect(Request.RawUrl);

    }
    protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        TableCell UserName = GridView2.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0];

        MembershipUser user = Membership.GetUser(Convert.ToString(UserName.Text));

        if (e.CommandName.Equals("unsuspend"))
        {
            DVDTableAdapters.CustomerTableAdapter ta = new DVDTableAdapters.CustomerTableAdapter();
            ta.UpdateQuery(false, (Guid)user.ProviderUserKey);

            DVDTableAdapters.aspnet_MembershipTableAdapter ta1 = new DVDTableAdapters.aspnet_MembershipTableAdapter();
            ta1.UpdateStatusUser(true, (Guid)user.ProviderUserKey);
        }
        else 
        {
            DVDTableAdapters.CustomerTableAdapter ta = new DVDTableAdapters.CustomerTableAdapter();
            ta.DeleteUser((Guid)user.ProviderUserKey);

            DVDTableAdapters.aspnet_MembershipTableAdapter ta1 = new DVDTableAdapters.aspnet_MembershipTableAdapter();
            ta1.Delete((Guid)user.ProviderUserKey);
        }
        Response.Redirect(Request.RawUrl);
    }
}